import React, { useEffect } from "react";
import { View } from "@tarojs/components";
import AMapLoader from "@amap/amap-jsapi-loader";

export default () => {
  // todo 微信小程序不能显示 h5/web端都可以正常显示
  useEffect(() => {
    setTimeout(() => {
      AMapLoader.load({
        key: "9ba4da02ab6dddf2d3784c1960d8db71",
        version: "2.0",
        plugins: [],
      })
        .then((AMap) => {
          let amap = new AMap.Map("mapContainer", {
            zoom: 15,
            center: [112.5266, 27.91507],
          });
          let marker = new AMap.Marker({
            position: [112.5266, 27.91507],
          });
          amap.add(marker);
        })
        .catch((e) => {
          console.error("Error loading AMap:", e);
        });
    }, 1000); // 延迟1秒
  }, []);

  return (
    <View style={{ width: "400px", height: "800px" }}>
      <View id="mapContainer" style={{ width: "100%", height: "100%" }}></View>
    </View>
  );
};
